<?php

class PasswordController extends Controller {

    /**
     * Declares class-based actions.
     */
    public function actions() {
        return array(
            // captcha action renders the CAPTCHA image
            // this is used by the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'backColor'=>0x333333,
                'padding' => 0,
                'height' => 40,
//                'minLength' => 4,
//                'maxLength' => 4,
            ),
        );
    }

    /**
     * Displays the login page
     */
    public function actionLogin() {
        $this->layout = false;
        $form = new LoginForm;
        // collect user input data
        if (isset($_POST['LoginForm'])) {
            $form->attributes = $_POST['LoginForm'];
            // validate user input and redirect to previous page if valid
            if($form->validate())
                $this->redirect(Yii::app()->user->returnUrl);
        }
        // display the login form
        $this->render('login', array('form' => $form));
    }

    /**
     * Logout the current user and redirect to homepage.
     */
    public function actionLogout() {
        Yii::app()->user->logout();
        $this->redirect(Yii::app()->homeUrl);
    }
}